package TempalteCode;

public class ConcreteIterator implements IIterator {

    private ConcreteAggregate concreteAggregate;

    private int cursor;

    public ConcreteIterator( ConcreteAggregate aggregate ){
        this.concreteAggregate = aggregate;
        cursor = aggregate.list.size();
    }

    @Override
    public void moveFirst() {
        if (cursor>0){
            this.cursor=0;
        }
    }

    @Override
    public void moveNext() {
        if (hasNext()){
            this.cursor++;
        }

    }

    @Override
    public boolean hasNext() {
        if(cursor==this.concreteAggregate.list.size()){
            return  false;
        }else {
            return true;
        }
    }

    @Override
    public Object currentItme() {
        return "名称：\t"+this.concreteAggregate.list.get(cursor);
    }

    @Override
    public void addObject(Object object) {
        this.concreteAggregate.add(object);
    }

    @Override
    public boolean removeObject(Object object) {
        return this.concreteAggregate.remove(object);
    }

}
